package edu.scut.course_management.dto;

import java.util.HashMap;
import java.util.Map;

import edu.scut.course_management.po.Student;

/**
 * 新增学生信息的数据传输对象
 * 
 * @author sherry
 */
public class RequestStudentDTO {
    
    private String studentId;
    private String name;
    private Boolean male;
    private String address;
    private String phoneNumber;
    private Integer majorId;
    private String enrollmentYear;
    private String className;

    // 用于查询学生信息
    private Integer departmentId;

    public RequestStudentDTO(String studentId, String name, Boolean male, String address, String phoneNumber, Integer majorId, String enrollmentYear, String className, Integer departmentId) {
        this.studentId = studentId;
        this.name = name;
        this.male = male;
        this.address = address;
        this.phoneNumber = phoneNumber;
        this.majorId = majorId;
        this.enrollmentYear = enrollmentYear;
        this.className = className;
        this.departmentId = departmentId;
    }

    public RequestStudentDTO() {
    }

    public String getStudentId() {
        return studentId;
    }

    public void setStudentId(String studentId) {
        this.studentId = studentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isMale() {
        return male;
    }

    public void setMale(boolean male) {
        this.male = male;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Integer getMajorId() {
        return majorId;
    }

    public void setMajorId(Integer majorId) {
        this.majorId = majorId;
    }

    public Integer getDepartmentId() {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) {
        this.departmentId = departmentId;
    }

    public String getEnrollmentYear() {
        return enrollmentYear;
    }

    public void setEnrollmentYear(String enrollmentYear) {
        this.enrollmentYear = enrollmentYear;
    }

    public String getClassName() {
        return className;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public boolean checkParamValidity(boolean isAdd) {
        //新增用户的参数检测
        if (isAdd){
            if (studentId.length() != 12) {
                return false;
            }
            else if (name == null || name.trim().isEmpty()) {
                return false;
            }
            else if (male == null) {
                return false;
            }
            else if (majorId == null){
                return false;
            }
            else if (enrollmentYear == null || enrollmentYear.trim().isEmpty()) {
                return false;
            }
            else if (className == null || className.trim().isEmpty()) {
                return false;
            }
            else {
                return true;
            }   
        }  
        // 查询用户信息的参数检测
        else {
            // 至少有一个查询条件
            if ((studentId != null && !studentId.trim().isEmpty()) || (name != null && !studentId.trim().isEmpty()) || 
                    (departmentId != null) || (majorId != null) || (enrollmentYear != null && !enrollmentYear.trim().isEmpty()) || 
                    (className != null && !className.trim().isEmpty())) {
                if ((majorId != null) && (departmentId == null)) {
                    return false;
                }
                // 级联查询
                else if ((enrollmentYear != null) && ((majorId == null) || (departmentId == null))) {
                    return false;
                }
                else if ((className != null) && ((majorId == null) || (departmentId == null) || (enrollmentYear == null))) {
                    return false;
                } 
                else {
                    return true;
                }
            }
            return false;
        }
    }

    public Student toObjectStudent() {
        return new Student(1, studentId, null, name, male, address,
            phoneNumber, majorId, enrollmentYear, className);
    }

    // 查询学生信息条件
    public Map<String, Object> queryStudent () {
        Map<String, Object> map = new HashMap<>();
        map.put("studentId", studentId);
        map.put("name", name);
        map.put("departmentId", departmentId);
        map.put("majorId", majorId);
        map.put("enrollmentYear", enrollmentYear);
        map.put("className", className);
        return map;
    }

    @Override
    public String toString() {
        return "RequestStudentDTO {" + 
                "address=" + address + 
                ", className=" + className + 
                ", departmentId=" + departmentId + 
                ", enrollmentYear=" + enrollmentYear + 
                ", majorId=" + majorId + 
                ", male=" + male + 
                ", name=" + name
                + ", phoneNumber=" + phoneNumber + 
                ", studentId=" + studentId + 
                "}";
    }

    
}
